import QtQuick 1.1
import com.nokia.meego 1.0

/**
 * A TextArea that properly changes it's colors if the theme is
 * inverted. This is useful for the case that the TextArea is
 * used as readOnly field only anyways like for example the
 * case at the console-output where we like to properly display
 * an inverted theme if the theme is inverted rather then the
 * default white background with black text on it.
 */
TextArea {
    wrapMode: TextEdit.NoWrap

    property variant defaultTextColor: null
    property variant defaultBackground: null
    property variant defaultBackgroundDisabled: null
    property variant defaultBackgroundSelected: null

    function themeInvertedChanged() {
        if (defaultTextColor == null)
            return;
        themedTextAreaStyle.textColor = theme.inverted ? '#ffffff' : defaultTextColor
        themedTextAreaStyle.background = theme.inverted ? '' : defaultBackground
        themedTextAreaStyle.backgroundDisabled = theme.inverted ? '' : defaultBackgroundDisabled
        themedTextAreaStyle.backgroundSelected = theme.inverted ? '' : defaultBackgroundSelected
    }

    property variant themeinverted: theme.inverted
    onThemeinvertedChanged: {
        themeInvertedChanged()
    }

    Component.onCompleted: {
        defaultTextColor = themedTextAreaStyle.textColor;
        defaultBackground = themedTextAreaStyle.background;
        defaultBackgroundDisabled = themedTextAreaStyle.backgroundDisabled;
        defaultBackgroundSelected = themedTextAreaStyle.backgroundSelected;

        themeInvertedChanged()
    }

    style: TextAreaStyle {
        id: themedTextAreaStyle

        //TODO not sure about following properties...
        //promptTextColor: '#ff0000'
        //selectedTextColor: '#ff0000'
        //selectionColor: '#ff0000'
        //backgroundError: '#ff0000'
    }
}
